package com.thering.movie_servers.movies.controller;

import com.thering.movie_servers.movies.pojo.Movie;
import com.thering.movie_servers.movies.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author: the_ring
 * date: 2022/5/11
 * function: 电影控制类
 */
@RestController
@CrossOrigin()
public class MovieController {

    @Autowired
    MovieService movieService;

    @GetMapping("/movies")
    public List<Movie> getAllMovies() {
        List<Movie> movies = movieService.list();
        return movies;
    }

    @GetMapping("/movies/{type}")
    public List<Movie> getMoviesByType(@PathVariable(value = "type") String type) {
        System.out.println(type);
        List<Movie> movies = movieService.getMoviesByType(type);
        return movies;
    }
}
